package conservare.modelo.banco;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="TB_SEQUENCIAL_BOLETO")
public class SequencialBoleto implements Serializable{

	private static final long serialVersionUID = 1292087823153874428L;

	@EmbeddedId
	private SequencialBoletoPK id;
	
	@Column(name="inicial")
	private Integer sequencialInicial = 0;
	
	@Column(name="atual")
	private Integer sequencialCorrente = 0;
	
	@Column(name="final")
	private Integer sequencialFinal = 0;
	
	
	public SequencialBoleto(){}
	
	
	public SequencialBoleto(SequencialBoletoPK sequencialBoletoPK) {
		super();
		this.id = sequencialBoletoPK;
	}

	public SequencialBoletoPK getId() {
		return id;
	}


	public int obterProximoSequencial(){
		
		this.sequencialCorrente = this.sequencialCorrente == null ? 0 : this.sequencialCorrente;
		this.sequencialCorrente = this.sequencialCorrente + 1;
		
		this.sequencialCorrente = this.sequencialCorrente >= this.sequencialFinal ? 1 : this.sequencialCorrente;
		
		return this.sequencialCorrente;
		
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}




	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SequencialBoleto other = (SequencialBoleto) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
